<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>编辑管理员</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"><!-- 确保适当的绘制和触屏缩放 -->
    <link rel="stylesheet" href="{$url_css}bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="{$url_css}admin.css" type="text/css">

    <script type="text/javascript" src="{$url_js}jquery-1.12.0.min.js"></script>
    <style type="text/css">
        .checkbox{
            margin: 0;
        }
    </style>
</head>
<body>
    <div class="container" style="width:96%">
        <div class="page-header">
              <h3>编辑管理员-- {$user.AdminUserName}</h3>
        </div>
        
        <form method="post">
        <table class="table table-bordered " align="center">
            <tbody>
                <tr>
                    <td class="col-xs-2">
                        <div class="input-group">
                            <div class="input-group-addon">用户ID</div>
                            <input type="text" class="form-control" name="user_name" placeholder="" value="{$user.AdminUserId}" readonly>
                        </div>
                    </td>
                    <td class="col-xs-2">
                        <div class="input-group">
                            <div class="input-group-addon">用户名</div>
                            <input type="text" class="form-control" name="user_name" placeholder="" value="{$user.AdminUserName}" readonly>
                        </div>
                    </td>
                    <td class="col-xs-8"></td>
                </tr>
                <tr>
                    <td class="col-xs-2">
                        <div class="input-group">
                            <div class="input-group-addon">管理组</div>
                            <select name="auth_group" class="form-control">
                                {$groupselect}
                            </select>
                        </div>
                    </td>
                    <td class="col-xs-2">
                        <div class="input-group">
                            <div class="input-group-addon">真实姓名</div>
                            <input type="text" class="form-control" name="user_name" placeholder="" value="{$user.AdminUserName}">
                        </div>
                    </td>
                    <td class="col-xs-8"></td>
                </tr>
            </tbody>
        </table>
        <table class="table table-bordered " align="center">
                <tr><td colspan="4"><h4><strong>权限设置</strong></h4></td></tr>
                <!-- 一级菜单 -->
                {foreach $menu as $v}
                    <tr>
                        <td colspan="3" class="col-xs-12">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" {if isset($auth[$v.Key])}checked="checked"{/if} value="{$v.Key}" name="menu[]" id="g_{$v.AdminMenuId}"> {$v.Name}
                                    {if (isset($auth[$v.Key]))}
                                        <span class="label label-primary">个人</span>
                                    {/if}
                                    {if isset($group_auth[$v.Key])}
                                        <span class="label label-success">管理组</span>
                                    {/if}
                                </label>
                              </div>
                        </td>
                    </tr>
                    <!-- 二级菜单 -->
                    {foreach $v.child as $v2}
                        <tr>
                            <td><div style="width:20px;"></div></td>
                            <td colspan="2" class="col-xs-12">
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" {if isset($auth[$v2.Key])}checked="checked"{/if} value="{$v2.Key}" name="menu[]" id="g_{$v.AdminMenuId}_{$v2.AdminMenuId}"> {$v2.Name}
                                        {if (isset($auth[$v2.Key]))}
                                            <span class="label label-primary">个人</span>
                                        {/if}
                                        {if isset($group_auth[$v2.Key])}
                                            <span class="label label-success">管理组</span>
                                        {/if}
                                    </label>
                                  </div>
                            </td>
                        </tr>
                        <!-- 三级菜单 -->
                        {foreach $v2.child as $v3}
                            <tr>
                                <td><div style="width:20px;"></div></td>
                                <td><div style="width:20px;"></div></td>
                                <td colspan="1" class="col-xs-12">
                                    <div class="checkbox">
                                        <label>
                                            <input type="checkbox" {if isset($auth[$v3.Key])}checked="checked"{/if} value="{$v3.Key}" name="menu[]" id="g_{$v.AdminMenuId}_{$v2.AdminMenuId}_{$v3.AdminMenuId}"> {$v3.Name}
                                            {if (isset($auth[$v3.Key]))}
                                                <span class="label label-primary">个人</span>
                                            {/if}
                                            {if isset($group_auth[$v3.Key])}
                                                <span class="label label-success">管理组</span>
                                            {/if}
                                        </label>
                                      </div>
                                </td>
                            </tr>
                        {/foreach}
                    {/foreach}
                {/foreach}
                <tr>
                    <td colspan="4">
                        <input type="submit" value="保存" class="btn btn-primary btn-sm">
                        <input type="button" onclick="history.back()" value="取消" class="btn btn-primary btn-sm">
                        <button class="btn btn-default btn-sm" onclick="location.reload();return false;">重置</button>

                    </td>
                </tr>
            </tbody>
        </table>
        </form>
    </div>

    <script type="text/javascript">
        {literal}
            $(".checkbox").on('click', 'input:checkbox', function(){
                var sta = $(this).prop("checked");
                var mid = $(this).attr("id").split("_");
                var id = $(this).attr("id");
                if (sta){
                    if (mid.length == 4){
                        $("#g_" + mid[1]).prop("checked", true);
                        $("#g_" + mid[1] + "_" + mid[2]).prop("checked", true);
                    }else if(mid.length == 3){
                        $("#g_" + mid[1]).prop("checked", true);
                    }
                }else{
                    $("input:checkbox[id^='"+id+"']").prop("checked", false);
                }
            });
        {/literal}
    </script>
</body>
<html>
    